/*
Copyright (C) 2021-2025 Casa Xu (also Zhiyan Xu) from HIT

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

/*
 * LOS_DataTran.h
 *
 *  Created on: 2022年7月10日
 *      Author: 64435
 */

#ifndef PERIPHERAL_LAYER_INC_LOS_DATATRAN_H_
#define PERIPHERAL_LAYER_INC_LOS_DATATRAN_H_

#include "LOS_SYS.h"

typedef struct LOS_DataTran_State
{
    uint8_t VAL;    //数据有效性标志，0：有效， 其他值：无效
    uint8_t CMD;    //开关机指令状态,发送开机指令后置1，发送关机指令后置0
    uint8_t PWR;    //电源状态，读取电源遥测，通电为1，断电为0
    uint8_t MSG;    //通信状态，通信正常为0，通信异常为其他值
    uint8_t SWNUM;  //开关号，指示
    uint8_t REC;    //CAN识别标志位,0:未识别  1：识别
    /* 数传状态量 */
    uint8_t FTP_FileNum;        //当前发送文件序号
    uint32_t FTP_FileSize;      //当前发送文件大小
    uint32_t boottime;          //记录数传的上电时间
    uint8_t ENWDT;              //数传看门狗使能，0xAA使能，其他禁能
    uint32_t askcnt;             //遥测计数器
}LOS_DT_t;

extern LOS_DT_t STA_DT;

extern uint8_t TMPACK_DTBasic[91];

void LOS_DT_CMD(uint8_t* cmd);
void LOS_CAN_BaseBandCallBack(LOS_CANMSG_t* can_re);
void LOS_DTCH_PWROn();
void LOS_DTCH_PWROff();
void LOS_DTBB_PWROn();
void LOS_DTBB_PWROff();
void LOS_DT_CMD0BYTE(uint8_t cmd);
void LOS_DT_CMD1BYTE(uint8_t cmd, uint8_t arg);
void LOS_DT_CMD4BYTE(uint8_t cmd, uint8_t* arg);
void LOS_DT_CMD8BYTE(uint8_t cmd, uint8_t* arg);
void LOS_DT_CMD16BYTE(uint8_t cmd, uint8_t* arg);
void LOS_DT_SetFile(uint8_t filenum);
void LOS_DT_ReadBlock(uint32_t offset, uint32_t length);
void LOS_DT_TMSend(uint8_t* tmmsg, uint16_t datalen);


#endif /* PERIPHERAL_LAYER_INC_LOS_DATATRAN_H_ */
